﻿Imports System.Collections.Generic
Imports System.Linq
Imports Crystal.Common.Model
Imports System.Data
Imports System.Linq.Expressions
Imports System.IO
Imports System.ComponentModel
Imports Crystal.CLL
Imports System.Data.SqlClient

'Namespace CrystalDataHub.BLL

Public Class UploadeSourceManager
    Implements IDisposable

#Region "Fields"

#End Region

#Region "Constructors"

    Public Sub New()
    End Sub

#End Region

#Region "Methods"

    Public Sub Dispose() Implements IDisposable.Dispose
    End Sub

    Public Function GetClientList() As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_GetClientSummary")
        Return Idrdata
    End Function

    Public Function GetProjectYear(ByVal ClientID As Int16) As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_GetProjectYear", New Object() {ClientID})
        Return Idrdata
    End Function

    Public Function GetProjectSummary(ByVal ClientID As Int16, ByVal Year As Integer) As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_GetProjectSummary", New Object() {ClientID, Year})
        Return Idrdata
    End Function

    Public Function GetProjectListings(ByVal ProjectID As Integer) As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_GetProjectListingSummary", New Object() {ProjectID})
        Return Idrdata
    End Function

    Public Function GeteSourceTypeList() As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_GeteSourceTypeList")
        Return Idrdata
    End Function

    Public Function GeteSourceNames(ByVal SourceTypeCode As String) As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_GetImportSources", New Object() {SourceTypeCode})
        Return Idrdata
    End Function

    Public Function GeteTemplates(ByVal ESourceID As Integer) As IDataReader
        Dim Idrdata As IDataReader = Nothing
        Idrdata = DataFactory.CreateDataBase().ExecuteReader("CR_sp_GetImportTemplates", New Object() {ESourceID})
        Return Idrdata
    End Function

    Public Sub InsertDataEntity(ByVal pintESourceID As Int16, ByVal pstrSourceName As String, ByVal pintListingID As Integer, ByVal pintProjectID As Integer, ByVal pintUserID As Int16, ByRef pintEntityID As Integer, ByRef pintResult As Integer, ByVal pdtSourceDate As Date)
        Dim cmd As New SqlCommand
        Dim sqlParam(7) As SqlParameter
        cmd.CommandTimeout = 0
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "CR_sp_EDS_InsertDataEntity"

        sqlParam(0) = New SqlParameter("@ESourceID", pintESourceID)
        cmd.Parameters.Add(sqlParam(0))
        sqlParam(1) = New SqlParameter("@SourceName", pstrSourceName)
        cmd.Parameters.Add(sqlParam(1))
        sqlParam(2) = New SqlParameter("@ListingID", pintListingID)
        cmd.Parameters.Add(sqlParam(2))
        sqlParam(3) = New SqlParameter("@ProjectID", pintProjectID)
        cmd.Parameters.Add(sqlParam(3))
        sqlParam(4) = New SqlParameter("@UserID", pintUserID)
        cmd.Parameters.Add(sqlParam(4))

        sqlParam(5) = New SqlParameter("@SourceDate", pdtSourceDate)
        cmd.Parameters.Add(sqlParam(5))

        sqlParam(6) = New SqlParameter("@Result", SqlDbType.Int)
        cmd.Parameters.Add(sqlParam(6))
        sqlParam(6).Direction = ParameterDirection.Output

        sqlParam(7) = New SqlParameter("@EntityID", SqlDbType.Int)
        cmd.Parameters.Add(sqlParam(7))
        sqlParam(7).Direction = ParameterDirection.Output

        CreateDataBase.ExecuteNonQuery(cmd)
        If (cmd.Parameters(6).Value IsNot DBNull.Value) Then
            pintResult = CInt(cmd.Parameters(6).Value)
        End If

        If (cmd.Parameters(7).Value IsNot DBNull.Value) Then
            pintEntityID = CInt(cmd.Parameters(7).Value)
        End If
    End Sub

    Public Function GetNextValidProject(ByVal pintProjectID As Integer) As IDataReader
        Return DataFactory.CreateDataBase().ExecuteReader("CR_sp_EDS_GetNextValidProject", New Object() {pintProjectID})
    End Function

    Public Function CheckOpenHubForm(ByVal pintProjectID As Integer, ByVal pintUserID As Short) As Integer
        Return DataFactory.CreateDataBase().ExecuteScalar("CR_sp_FL_CheckOpenHubForm", New Object() {pintProjectID, pintUserID})
    End Function

    Public Sub OpenHubForm(ByVal pintProjectID As Integer, ByVal pintUserID As Integer, ByVal pstrForm As String)
        DataFactory.CreateDataBase().ExecuteNonQuery("CR_sp_DE_FormOpened", New Object() {pintProjectID, pintUserID, pstrForm})
    End Sub

#End Region

End Class
'End Namespace
